import 'package:flutter_axrjc/datasource/network/api/LightApi.dart';
import 'package:flutter_axrjc/datasource/network/bean/MonthReportBean.dart';
import 'package:get/get.dart';
import 'package:webview_flutter/webview_flutter.dart';

import 'state.dart';

class ReportMonthDetailLogic extends GetxController {
  final ReportMonthDetailState state = ReportMonthDetailState();
  late MonthReportBean bean;
  WebViewController webViewController = WebViewController();
  @override
  void onInit() {
    super.onInit();
    bean = Get.arguments as MonthReportBean;
    getTop();

    webViewController.setJavaScriptMode(JavaScriptMode.unrestricted);
    getECahr();
  }

  Future<void> getTop() async {
    state.topData.value = await LightApi.getReportTopData("${bean.fixtureId}");
  }

  Future<void> getECahr() async {
    String html = await LightApi.getECharData(
        queryTimeType: state.queryTimeType.value,
        fixtureId: "${bean.fixtureId}");
    if (html.isNotEmpty) {
      webViewController.loadHtmlString(html);
    }
  }
}
